<#include "../../select.ftl" />
<#assign security=JspTaglibs["/WEB-INF/security.tld"] />
<!-- Modal -->
<div class="modal-dialog wide" style="width: 620px;">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title" id="myModalLabel">
            <#if user??>
                <#if user.id??>
                    编辑用户
                <#else>
                    新增用户
                </#if>
            </#if>
            </h4>
        </div>
        <div class="modal-body">
            <div id="errorMessage"><#include "../../message.ftl" /></div>
            <form class="form-horizontal" role="form" id="userForm" method="post"
                  action="${absoluteContextPath}/system/user/save">
            <#if user??>
                <#if user.id??>
                    <input type="hidden" name="id" value="${user.id}"/>
                <#else>
                    <input type="hidden" name="id" value=""/>
                </#if>
            </#if>
                <div class="row">
                    <div class="form-group col-md-6">
                        <label class="col-sm-4 control-label">登录名称<sup style="color: red">*</sup></label>

                        <div class="col-sm-8">
                        <#if user.loginName??>
                            <input name="loginName" value="${user.loginName!''}" type="text" class="form-control"
                                   readonly="readonly"/>
                        <#else>
                            <input name="loginName" value="" type="text" class="form-control"/>
                        </#if>
                        </div>
                    </div>
                    <div class="form-group col-md-6">
                        <label class="col-sm-4 control-label">密码<sup style="color: red">*</sup></label>

                        <div class="col-sm-8">
                        <#if user.password??>
                            <input name="password" value="${user.password!''}" type="password" readonly
                                   class="form-control"/>
                        <#else>
                            <input name="password" value="${user.password!''}" type="text" class="form-control"/>
                        </#if>
                        </div>
                    </div>
                    <div class="form-group col-md-6">
                        <label class="col-sm-4 control-label">用户名称<sup style="color: red">*</sup></label>

                        <div class="col-sm-8">
                            <input name="userName" value="${user.userName!''}" type="text" class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group col-md-6">
                        <label class="col-sm-4 control-label">性别<sup style="color: red">*</sup></label>

                        <div class="col-sm-8">
                        <@select name="sex" value="${user.sex!''}" list=sexTypeList class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group col-md-6">
                        <label class="col-sm-4 control-label">所属机构<sup style="color: red">*</sup></label>

                        <div class="col-sm-8">
                            <div class="input-group">
                                <input name="orgName" value="${user.orgName!''}" type="text" class="form-control"
                                       readonly="true"/>
                                <input name="orgId" value="${user.orgId!''}" type="hidden" class="form-control">
                                <span class="input-group-addon" onclick="doSelctOrg(this);"><i class="fa fa-search"></i></span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group col-md-6">
                        <label class="col-sm-4 control-label">电子邮箱</label>

                        <div class="col-sm-8">
                            <input name="email" value="${user.email!''}" type="text" class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group col-md-6">
                        <label class="col-sm-4 control-label">用户状态<sup style="color: red">*</sup></label>

                        <div class="col-sm-8">
                        <@select name="status" value="${user.status!''}" list=userStatusList class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group col-md-6">
                        <label class="col-sm-4 control-label">用户类型<sup style="color: red">*</sup></label>

                        <div class="col-sm-8">
                        <@select name="userType" value="${user.userType!''}" list=userTypeList class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group col-md-6">
                        <label class="col-sm-4 control-label">排序号</label>

                        <div class="col-sm-8">
                            <input name="sortNo" value="${user.sortNo!''}" type="text" class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label class="col-sm-2 control-label">备注</label>

                        <div class="col-sm-10">
                            <textarea name="remark" rows="6" cols="20" style="width: 429px">${user.remark!''}</textarea>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
            <button type="button" class="btn btn-primary" onclick="save();">保存</button>
        </div>
    </div>
</div>
<script>
    $(function () {
        $(".chosen-select").chosen({disable_search_threshold: 10});
    });
    function save() {
        $("#" + "userForm").ajaxSubmit({
            success: function (data) {
                data = JSON.parse(data);
                if (data.returnCode == 1) {
                    $('#myModal').modal("hide");
                    $.showMessage({parentId: "showMessage", message: "信息保存成功！", type: "success"});
                    refreshTable();
                } else {
                    $.showMessage({parentId: "errorMessage", message: "<strong>错误信息</strong>：" + data.returnMsg, type: "error"});
                }
            }
        });
    }
</script>